<template>
	<view class="">
		<view class="box" v-if="alartsData.length>0">
			<view class="cardBg" v-for="(item,index) in alartsData" :key="index">
				<view class="top">
					<view class="list">
						<text class="title">告警对象：</text>
						<text class="content"> {{item.Name || '--'}}</text>
					</view>
					<view class="list">
						<text
							:class="item.AlarmLevel=='M1'?'alarmWarning':'alarmError'">{{item.AlarmLevel || 'M0'}}</text>
					</view>
				</view>
				<view class="bottom">
					<view class="list">
						<text class="title">告警内容：</text>
						<text class="contentValue">{{item.Value}}</text>
					</view>
					<view class="list">
						<text class="title">告警时间：</text>
						<text class="content">{{item.Time}}</text>
					</view>
				</view>
			</view>
		</view>
		<u-loading-page style="z-index:9" :loading="loading" loading-text="loading..." bg-color="rgb(0, 0, 0,.3)">
		</u-loading-page>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				alartsData: [],
				loading: true
			}
		},
		props: {
			queryData: {
				type: Object,
				default: function() {
					return {};
				}
			}
		},
		onReady() {},
		methods: {
			async getGwData() {
				const db = uniCloud.database()
				let str = 'ASCG123456789/rs485b/1'
				const [sn, port, addr] = str.split('/')
				const res = await db.collection('gateways').where({
					category: 'realtime',
					name: sn
				}).get()
				const result = res.result.data[0].ports[port].Device[addr - 1].data
				this.alartsData = result.filter(item => item.PropertyType === 'alarm')
				this.loading = false
			},
		},
		created() {
			this.getGwData()
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		.cardBg {
			.top {
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1px solid rgba(228, 230, 232, 1);
				padding: 10px 0px;

				.list {
					display: flex;
					align-items: center;
					justify-content: space-between;
				}

			}

			.bottom {
				padding: 10px 0 0px;

				.list {
					line-height: 30px;
				}
			}

			.alarmWarning {
				font-size: 12px;
				letter-spacing: 0px;
				line-height: 16.41px;
				color: #ff9900;
				text-align: left;
				vertical-align: top;
				border: 1px solid #ff9900;
				border-radius: 8rpx;
				padding: 2px 6px;
			}

			.alarmError {
				font-size: 12px;
				letter-spacing: 0px;
				line-height: 16.41px;
				color: #fa3534;
				text-align: left;
				vertical-align: top;
				border: 1px solid #fa3534;
				border-radius: 8rpx;
				padding: 2px 6px;
			}

			.title {
				font-size: 15px;
				font-weight: 400;
				letter-spacing: 0px;
				line-height: 17.58px;
				color: rgba(10, 22, 41, 1);
				text-align: left;
				vertical-align: top;
			}

			.contentValue {
				font-size: 16px;
				font-weight: 400;
				letter-spacing: 0px;
				line-height: 16.41px;
				color: #3c9cff;
				text-align: left;
				vertical-align: top;
			}

			.content {
				font-size: 14px;
				font-weight: 400;
				letter-spacing: 0px;
				line-height: 16.41px;
				color: rgba(145, 146, 158, 1);
				text-align: left;
				display: inline-block;
				width: 180px;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}
		}
	}
</style>